<?php
session_start();
ob_start();

define('INDEX',true);
// Include required files
// Include required files
require("../_config/config.php");
require("../_config/db_connection.php");
require("../common/functions_common.php");
require("../common/functions_mysql.php");
require("../common/functions_jcas.php");
require("../common/init.php");

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML 3.2//EN">
<HTML  >
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="MSThemeCompatible" content="Yes">
<meta name="copyright" content="Huynh Ngoc Hung (c) 2004">
<TITLE>Insert Image</TITLE>
<style>
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	color:#333333;
}
.button
{
font-size:11px;
padding:1px 1px 1px 1px;
font-family:tahoma ;
cursor:hand
}
</style>
<script language="javascript">
function ask(url,msg)
{
	if (!confirm(msg))
	{ //do nothing
	}
	else  window.location = url;
}
</script>
</head>

<BODY id=bdy style="background: threedface; color: windowtext;" scroll=no>
<?php
// Upload file
if($_GET['delete'])
{
	unlink('../../'.$cfg['upload_folder'].'/'.$_GET['delete']);
}
if($_POST['upload'])
{
	$file_name = $_FILES["file"]["name"];
	if($file_name)
	{
		$name = substr(strtolower($file_name),0,strlen($file_name)-4);
		$ext = substr(strtolower($file_name),-3);
		$file_size = $_FILES['file']["size"];
		$upload_file_name = $name.'_'.$time.".".$ext;
		$upload_process = true;
		// Check file type 
		if($cfg["allowed_file_type"] && !eregi($ext,$cfg["allowed_file_type"]))
		{
			$message = "<font color='red' style=\"font-size:11px\">ERROR! File type is not allowed (Allowed: ".$cfg["allowed_file_type"].") !</font>";
			$upload_process = false;
		}
		// Check file size 
		if($cfg["max_file_size"] && $file_size > $cfg["max_file_size"]*1024)
		{
			$message = "<font color='red' style=\"font-size:11px\">ERROR! File size is too big !</font>";
			$upload_process = false;
		}
		// Do upload file
		if($upload_process)
		{
			if (copy($_FILES['file']['tmp_name'],'../../'.$cfg['upload_folder'].''.$upload_file_name)) 
			{
				?>
				<table width="96%"  border="0" cellspacing="0" cellpadding="1" align="center">
				  <tr>
					<td style="font-size:10px;font-family:MS Shell Dlg ">URL for uploaded file:</td>
				  </tr>
				  <tr>
					<td><input type="text" size="75" style="font-size:11px;font-family:arial " value="<?php echo $cfg['site_url'].'/'.$cfg['upload_folder'].$upload_file_name; ?>" readonly onFocus="select()" /></td>
				  </tr>
				  <tr>
					<td >
					<input type="button" value="Upload another file" class="button" onClick="window.location='upload_file.php'" />
					<input type="button" value="Delete this file" style="color:#990000" class="button" onClick="ask('upload_file.php?delete=<?php echo $upload_file_name?>','Do you want to DELETE this file?')"  />
					<input type="button" value="Close" class="button" onClick="window.close()"  />
					</td>
				  </tr>
				</table>
				<?php
				 $show_content = false;
			}
			else  $message = "<font color='red' style=\"font-size:11px\">ERROR! Can not upload file !</font>";
		}
	}
}

if(@$show_content)
{
?>
	<script language="javascript">
	function jsupload()
	{
		wait.style.display = "inline";
		//document.frm_upload.upload.disabled = true;
		return true;
	}
	</script>
	<table width="96%"  border="0" cellspacing="0" cellpadding="1" align="center">
	<form name="frm_upload" method="post" action="upload_file.php" enctype="multipart/form-data" onSubmit="return jsupload();">
	<tr>
	  <td colspan="2"  style="font-size:11px; font-family:MS Shell Dlg"><?php echo $message?>&nbsp;</td>
	  </tr>
	<tr>
		<td  style="font-size:11px; font-family:MS Shell Dlg">Upload file:</td>
		<td ><input type="file" name="file" size="48" style="font-size:10px;font-family:verdana,tahoma " /></td>
	  </tr>
	  <tr>
		<td  style="font-size:11px; font-family:MS Shell Dlg">&nbsp;</td>
		<td><input type="submit" name="upload"  id="upload" value="Upload this file" class="button"  />
			<input type="button" value="Cancel" class="button" onClick="window.close()"  />
			<div id="wait" style="display:none" align="right"><img src="../images/loading.gif"></div>
			</td>
	  </tr>
	</form>
	</table>
<?php
}
?>

</body>
</html>
<?php
$DB->close();
ob_end_flush();
?>